package com.controller.jkt;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.StpUtil;
import com.entity.Checker;
import com.service.jkt.RegisterbookService;
import com.service.jkt.ShenService;
import com.service.jkt.impl.ShenServiceImpl;
import com.util.gzp.AjaxResponse;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@Api(tags = "审核审批的接口")
@RequestMapping("/shen")
@Validated
public class ShenController {
    @Resource
    private ShenService shenService;
    @Resource
    private RegisterbookService registerbookService;

    @PostMapping("/shenhe")
    @ApiOperation(value = "提交 审核 的方法，返回AjaxResponse", response = Map.class)
    public AjaxResponse findsyq(
            @ApiParam("业务id") Integer serviceid,
         //   @ApiParam("审核人id") Integer reviewerid,
            @ApiParam("审核人意见") String revieweropinion
    ) {
        int uid;
        try {
            uid = StpUtil.getLoginIdAsInt();
        }catch (NotLoginException e) {
            return AjaxResponse.success("请先进行登录!",500);
        }
        Checker cr = new Checker();
        cr.setServiceid(serviceid);
        cr.setReviewerid(uid);
        cr.setRevieweropinion(revieweropinion);
        return shenService.shenHe(cr);
    }

    @PostMapping("/shenpi")
    @ApiOperation(value = "提交 审批 的方法，返回AjaxResponse", response = Map.class)
    public AjaxResponse find(
            @ApiParam("业务id") Integer serviceid,
           // @ApiParam("终审人id")  String finalreviewerid,
            @ApiParam("终审人意见") String finalrevieweropinion
    ) {
        int uid;
        try {
            uid = StpUtil.getLoginIdAsInt();
        }catch (NotLoginException e) {
            return AjaxResponse.success("请先进行登录!",500);
        }
        Checker cr = new Checker();
        cr.setServiceid(serviceid);
        cr.setFinalreviewerid(uid+"");
        cr.setFinalrevieweropinion(finalrevieweropinion);
        return shenService.shenpi(cr);
    }



    @PostMapping("/dengjibu")
    @ApiImplicitParams({
           // @ApiImplicitParam(name = "hid",value = "楼盘id",required = true,dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "serviceid",value = "业务宗号",required = true,dataTypeClass = String.class),
            @ApiImplicitParam(name = "uid",value = "终审人id",required = true,dataTypeClass = String.class),
           // @ApiImplicitParam(name = "buildingid",value = "楼栋id",required = true,dataTypeClass = String.class),
            @ApiImplicitParam(name = "clientid",value = "客户id",required = true,dataTypeClass = String.class),
            @ApiImplicitParam(name = "roomid",value = "房屋id",required = true,dataTypeClass = String.class)
    })
    public AjaxResponse add(Integer serviceid,Integer uid,Integer clientid,Integer roomid){
        System.out.println("ShenController.add"+"---"+serviceid+"-----"+uid+"----"+clientid+"----"+roomid);
        registerbookService.addRegisterbook(serviceid,uid,clientid,roomid);
        return AjaxResponse.success("成功");
    }
}
